<template>
  <div>
    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: true }"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt=""
            style="max-width: 80px; font-size: 12px; font-style: italic"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <div slot="action" slot-scope="text, record" v-if="record.contractBpmStatus === '3'">
          <!--销售/项目负责人，申请发票-->
          <div v-has="'ContractSalePaymentCollection:edit'">
            <a v-if="record.bpmStatus === '1'" @click="saleApplyInvoiceHandleDetail(record, false)">申请</a>
            <template v-if="record.auditDataId">
              <a-divider type="vertical" v-if="record.auditDataId && record.bpmStatus === '1'" />
              <a-dropdown>
                <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
                <a-menu slot="overlay">
                  <a-menu-item>
                    <a @click="saleApplyInvoiceHandleDetail(record, true)">详情</a>
                  </a-menu-item>
                  <a-menu-item v-if="record.bpmStatus === '1'">
                    <a @click="startApplyInvoiceProcess(record)">发起流程</a>
                  </a-menu-item>
                  <a-menu-item v-if="record.bpmStatus !== '1'" @click="handleTrack(record)">审批进度</a-menu-item>
                </a-menu>
              </a-dropdown>
            </template>
          </div>
          <!-- 财务，回款确认 -->
          <span v-has="'ContractSalePaymentCollection:sure'">
            <a v-if="record.auditDataId" @click="saleApplyInvoiceHandleDetail(record, true)">详情</a>
            <a-divider type="vertical" v-if="record.auditDataId" />
            <a @click="handleEdit(record)">确认</a>
          </span>
        </div>
      </a-table>
    </div>

    <PostSaleQuestionDetailModal
      ref="PostSaleQuestionDetailModalForm"
      @ok="postSaleQuestionDetailOk"
    ></PostSaleQuestionDetailModal>
    <bpm-process-track-modal ref="bpmProcessTrackModal"></bpm-process-track-modal>
    <bpm-biz-task-deal-modal
      ref="taskDealModal"
      :path="path"
      :formData="formData"
      @ok="handleOk"
    ></bpm-biz-task-deal-modal>
  </div>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import ContractSaleApplyInvoiceModal from '@views/hifar/postsale/modules/PostSaleQuestionDetailModal'
import { getAction, postAction } from '@api/manage'
import { JeecgBpmListMixin } from '@/mixins/JeecgBpmListMixin'
import BpmBizTaskDealModal from '@views/modules/bpmbiz/common/BpmBizTaskDealModal'
import BpmProcessTrackModal from '@views/modules/bpmbiz/common/BpmProcessTrackModal'

export default {
  name: 'PostSaleQuestionDetailList',
  mixins: [JeecgBpmListMixin, mixinDevice],
  components: {
    ContractSaleApplyInvoiceModal,
    BpmBizTaskDealModal,
    BpmProcessTrackModal,
  },
  props: {
    mainId: {
      type: String,
      default: '',
      required: false,
    },
    // bpmStatus:{
    //   type:String,
    //   default:'',
    //   required:false
    // }
  },
  data() {
    return {
      description: '问题管理-售后问题明细页面',
      // 表头
      columns: [
        {
          title: '问题类型',
          align: 'center',
          dataIndex: 'questionType',
        },
        {
          title: '问题描述',
          dataIndex: 'questionDesc',
          align: 'center',
        },
        {
          title: '工时',
          dataIndex: 'workHours',
          align: 'center',
        },
        {
          title: '完成人',
          dataIndex: 'charger',
          align: 'center',
        },
        {
          title: '完成时间',
          dataIndex: 'completedDate',
          align: 'center',
        },
        {
          title: '问题状态',
          dataIndex: 'questionStatus',
          align: 'center',
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/postsale/postSaleQuestion/queryPostSaleQuestionItemByMainId',
        delete: '/contract/contractSalePaymentCollection/delete',
        deleteBatch: '/contract/contractSalePaymentCollection/deleteBatch',
        exportXlsUrl: '/contract/contractSalePaymentCollection/exportXls',
        importExcelUrl: 'contract/contractSalePaymentCollection/importExcel',
        queryById: 'contract/contractSalePaymentCollection/queryById',
        findByPaymentId: '/contract/contractSaleApplyInvoice/findByPaymentId',
      },
      flowCode: 'dev_hf_contract_sale_apply_invoice_001',
      dictOptions: {},
      superFieldList: [],
      queryModel: true,
    }
  },
  created() {
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    refresh(row) {
      this.queryParam.contractId = row.id
      this.loadData(1)
    },
    initDictConfig() {},
    saleApplyInvoiceHandleDetail(record, disableSubmit) {
      let saleApplyInvoice = {}
      let that = this
      getAction(this.url.findByPaymentId, { id: record.id }).then((res) => {
        if (res.success) {
          saleApplyInvoice = res.result
          that.$refs.saleApplyInvoiceModalForm.edit(saleApplyInvoice)
          that.$refs.saleApplyInvoiceModalForm.title = '销售合同开票信息'
          that.$refs.saleApplyInvoiceModalForm.disableSubmit = disableSubmit
        } else {
          this.$message.warning(res.message)
        }
      })
    },
    handleEdit(record) {
      let that = this
      getAction(this.url.queryById, { id: record.id }).then((res) => {
        if (res.success) {
          this.$refs.modalForm.edit(res.result)
          this.$refs.modalForm.title = '回款确认'
          this.$refs.modalForm.disableSubmit = false
        } else {
          this.$message.warning(res.message)
        }
      })
    },

    startApplyInvoiceProcess(record) {
      this.$confirm({
        title: '提示',
        content: '确认提交流程吗?',
        onOk: () => {
          let params = {
            flowCode: this.flowCode,
            id: record.auditDataId,
            formUrl: 'hifar/contract/modules/ContractSaleApplyInvoiceForm',
            formUrlMobile: '',
          }
          postAction(this.url.startProcess, params)
            .then((res) => {
              if (res.success) {
                this.$message.success(res.message)
                this.loadData()
                this.onClearSelected()
              } else {
                this.$message.warning(res.message)
              }
            })
            .catch((e) => {
              this.$message.warning('不识别的请求!')
            })
        },
      })
    },

    handleTrack(record) {
      var params = { flowCode: this.flowCode, dataId: record.auditDataId } //查询条件
      this.$refs.bpmProcessTrackModal.handleTrack(params)
      this.$refs.bpmProcessTrackModal.title = '审批跟踪记录'
    },

    postSaleQuestionDetailOk() {
      this.loadData(1)
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>